home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.20020314-20021006 / 000216_fdc@columbia.edu_Wed Jul 17 11:24:19 EDT 2002.msg < prev    next >
Text File  |  2020-01-01  |  3KB  |  74 lines

  1. Article: 13528 of comp.protocols.kermit.misc
  2. Path: newsmaster.cc.columbia.edu!news.columbia.edu!news-not-for-mail
  3. From: fdc@columbia.edu (Frank da Cruz)
  4. Newsgroups: comp.unix.programmer,comp.protocols.kermit.misc
  5. Subject: Re: FTP and multiple rename
  6. Date: 17 Jul 2002 11:22:36 -0400
  7. Organization: Columbia University
  8. Lines: 57
  9. Message-ID: <ah423s$2um$1@watsol.cc.columbia.edu>
  10. References: <ah3j66$2ct10@intra09.infocamere.it>
  11. NNTP-Posting-Host: watsol.cc.columbia.edu
  12. X-Trace: newsmaster.cc.columbia.edu 1026919357 6272 128.59.39.139 (17 Jul 2002 15:22:37 GMT)
  13. X-Complaints-To: postmaster@columbia.edu
  14. NNTP-Posting-Date: 17 Jul 2002 15:22:37 GMT
  15. Xref: newsmaster.cc.columbia.edu comp.unix.programmer:149197 comp.protocols.kermit.misc:13528
  16.  
  17. In article <ah3j66$2ct10@intra09.infocamere.it>,
  18. UomoOmbra <ombra@ombra.xxx> wrote:
  19. : I would like to ftp a server and rename all file in a directory to
  20. : filename.old  Hw can I do it?
  21. :
  22. It's best done with a scriptable FTP client:
  23.  
  24.   http://www.columbia.edu/kermit/ftpclient.html
  25.  
  26. Here's a tutorial on FTP scripting:
  27.  
  28.   http://www.columbia.edu/kermit/ftpscripts.html
  29.  
  30. Here's a script that does what you want:
  31.  
  32. ---(cut here)---
  33. ; Kermit FTP script to add ".old" suffix to all files in a server directory.
  34. ; Requires C-Kermit 8.0 (Unix) or Kermit 95 2.0 (Windows):
  35. ; http://www.columbia.edu/kermit/
  36. ;
  37. ; Change these as appropriate or convert them to command-line parameters.
  38. ; See: http://www.columbia.edu/kermit/ckscripts.html for an explanation.
  39. ;
  40. define user olga                                ; Username
  41. define host ftp.xyzcorp.com                     ; Hostname
  42. define dir  invoices                            ; Remote directory name
  43. define rfs  *                                   ; Remote file specification
  44. define tmp  filelist                            ; Local temp file name
  45.  
  46. ; The rest of the script doesn't need to be changed
  47.  
  48. ftp \m(host) /user:\m(user)                     ; Open the connection
  49. if fail stop 1 ftp open \m(host) failed         ; Check for failure
  50. ftp cd \m(dir)                                  ; CD to remote directory
  51. if fail stop 1 ftp cd \m(dir) failed            ; Check for failure
  52. ftp mget /namelist:\m(tmp) \m(rfs)              ; Get list of filenames
  53. if fail stop 1 ftp mget /namelist failed        ; Check for failure
  54. fopen /read \%c \m(tmp)                         ; Open the namelist file
  55. if fail stop 1 Open \m(tmp) failed: \f_errmsg() ; Check for failure
  56.  
  57. .\%n = 0                                        ; Initialize file counter
  58. set flag off                                    ; Error indication
  59. while not flag {                                ; Loop through files
  60.     fread \%c filename                          ; Read next filename
  61.     if fail break                               ; Failure is EOF
  62.     increment \%n                               ; Count the file
  63.     echo \%n. \m(filename)                      ; Give feedback
  64.     ftp rename \m(filename) \m(filename).old    ; Rename this file
  65.     if fail set flag on                         ; Check for failure
  66. }
  67. ftp dir                                         ; Done - Show remote files
  68. ftp bye                                         ; Disconnect from server
  69.  
  70. if flag stop 1 ftp rename failed: \m(filename)  ; Report any failure
  71. echo Files renamed: \%n                         ; Or report success
  72. end
  73.